package jp.eisbahn.mgapi.api;

/**
 * This abstract class provides a paging support.
 * @author Yoichiro Tanaka
 */
public abstract class AbstractPagingRequest implements Request {

    /** The start index. */
    private int startIndex = -1;

    /** The count. */
    private int count;

    /**
     * Retrieve the startIndex value.
     * @return The startIndex value.
     */
    public final int getStartIndex() {
        return startIndex;
    }

    /**
     * Set a startIndex value.
     * @param newStartIndex The startIndex to set
     */
    public final void setStartIndex(final int newStartIndex) {
        this.startIndex = newStartIndex;
    }

    /**
     * Retrieve the count value.
     * @return The count value.
     */
    public final int getCount() {
        return count;
    }

    /**
     * Set a count value.
     * @param newCount The count to set
     */
    public final void setCount(final int newCount) {
        this.count = newCount;
    }

    /**
     * Create and retrieve a query parameter regarding a start index.
     * @return The string array to be used for a query parameter.
     */
    protected final String[] getStartIndexQueryParameter() {
        if (startIndex >= 0) {
            return new String[] {"startIndex", String.valueOf(startIndex)};
        } else {
            return null;
        }
    }

    /**
     * Create and retrieve a query parameter regarding a count.
     * @return The string array to be used for a query parameter.
     */
    protected final String[] getCountQueryParameter() {
        if (count > 0) {
            return new String[] {"count", String.valueOf(count)};
        } else {
            return null;
        }
    }

}
